home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / ARGONET / PD / MATHS / RLAB / RLAB125.ZIP / !RLaB / rlib / set < prev    next >
Text File  |  1994-09-23  |  721b  |  39 lines

  1. //-------------------------------------------------------------------//
  2. //  set
  3.  
  4. //  Syntax:    set ( A )
  5.  
  6. //  Description:
  7.  
  8. //  The set function takes an vector argument (A), and returns a
  9. //  vector that is sorted in ascending order, and has no duplicate
  10. //  values. 
  11.  
  12. //  See Also: complement, intersection, union
  13. //-------------------------------------------------------------------//
  14.  
  15. set = function ( A )
  16. {
  17.   if (min (size (A)) != 1) 
  18.   {
  19.     error ("set: requires vector argument");
  20.   }
  21.  
  22.   i = j = 1;
  23.   a = sort (A).val;
  24.   while (i <= a.n)
  25.   {
  26.     tmp = find (a[i] == a);
  27.     if (tmp.n > 1) 
  28.     {
  29.       s[j] = a[tmp[1]];
  30.       i = i + tmp.n;
  31.     else
  32.       s[j] = a[tmp];
  33.       i++;
  34.     }
  35.     j++;
  36.   }
  37.   return s
  38. };
  39.